package com.jelly.web.modules.basics.dictionary.service.impl;

import com.jelly.common.util.StringUtils;
import com.jelly.web.modules.basics.dictionary.dao.DiyTypeAndDictionaryMapper;
import com.jelly.web.modules.basics.dictionary.domain.DiyTypeAndDictionary;
import com.jelly.web.modules.basics.dictionary.domain.DiyTypeAndDictionaryExample;
import com.jelly.web.modules.basics.dictionary.service.IDiyTypeAndDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @创建人 ql
 * @创建时间 2018-08-21 10:54
 * @项目名称 jelly
 * @功能描述: 字典扩展实现类
 **/
@Service
public class DiyTypeAndDictionaryServiceImpl implements IDiyTypeAndDictionaryService {

    @Autowired
    private DiyTypeAndDictionaryMapper diyTypeAndDictionaryMapper;


    /**
     * 获取字典扩展类型
     * @param isState(为空查询全部 不为空通过isState查询字典类型)
     * @return
     */
    @Override
    public List<DiyTypeAndDictionary> getDiyTypeAndDictionaryIsState(String isState) {

        DiyTypeAndDictionaryExample example = new DiyTypeAndDictionaryExample();


        if(StringUtils.isNotBlank(isState)){

            example.createCriteria().andIsStateEqualTo(isState).andDIsStateEqualTo(isState);

        }

        return diyTypeAndDictionaryMapper.selectByExample(example);

    }


    /**
     * 通过标识获取正常状态字典扩展类型
     * @param route
     * @return
     */
    @Override
    public DiyTypeAndDictionary getDiyTypeAndDictionary(String route) {

        return diyTypeAndDictionaryMapper.selectByPrimaryRoute(route);

    }


    /**
     * 条件字典扩展类型
     * @param
     * @return
     */
    @Override
    public List<DiyTypeAndDictionary> getDiyTypeAndDictionary(DiyTypeAndDictionary diyTypeAndDictionary) {
        DiyTypeAndDictionaryExample example = new DiyTypeAndDictionaryExample();
        DiyTypeAndDictionaryExample.Criteria criteria = example.createCriteria();

        if(StringUtils.isNotBlank(diyTypeAndDictionary.getDiyTypeName())){
            criteria.andDiyTypeNameEqualTo(diyTypeAndDictionary.getDiyTypeName());
        }

        if(StringUtils.isNotBlank(diyTypeAndDictionary.getDiyTypeRoute())){
            criteria.andDiyTypeRouteEqualTo(diyTypeAndDictionary.getDiyTypeRoute());
        }

        return diyTypeAndDictionaryMapper.selectByExample(example);
    }
}
